package com.kly.order.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.StringUtils;
import com.google.common.collect.Maps;
import com.kly.order.db.dao.ProductBenefitsDao;
import com.kly.order.db.entity.MemberEntity;
import com.kly.order.db.entity.ProductBenefitsEntity;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: 11437
* Date: 2023-06-14
* Time: 16:47:43.085
*/

@Repository
public class ProductBenefitsDaoImpl extends AbstractBaseMapper<ProductBenefitsEntity> implements ProductBenefitsDao {

    @Override
    public List<ProductBenefitsEntity> selectByProductCategory(Map<String, Object> params) {
        return this.getSqlSession().selectList(this.getStatement("selectByProductCategory"), params);
    }

    @Override
    public List<ProductBenefitsEntity> listProductBenefit(String appCode, Integer productCategory) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("deleted", 0);
        params.put("productCategory", productCategory);
        return this.getSqlSession().selectList(this.getStatement("listProductBenefit"), params);
    }

    @Override
    public ProductBenefitsEntity getProductBenefit(String appCode, Integer productCategory, Integer benefitCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("deleted", 0);
        params.put("productCategory", productCategory);
        params.put("benefitCode", benefitCode);
        return this.getSqlSession().selectOne(this.getStatement("getProductBenefit"), params);
    }

    @Override
    public List<ProductBenefitsEntity> listProductBenefitByBenefitCode(String appCode, Integer benefitCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("deleted", 0);
        params.put("benefitCode", benefitCode);
        return this.getSqlSession().selectList(this.getStatement("listProductBenefitByBenefitCode"), params);
    }

    @Override
    public Integer removeProductBenefit(String appCode, Integer benefitCode) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("benefitCode", benefitCode);
        return this.getSqlSession().update(this.getStatement("removeProductBenefit"), params);
    }

    @Override
    public Integer updateByBenefitCode(String appCode, Integer benefitCode, String tip, String content, String icon, Integer showFlag) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("appCode", appCode);
        params.put("benefitCode", benefitCode);
        if (StringUtils.isNotEmpty(tip)) {
            params.put("tip", tip);
        }
        if (StringUtils.isNotEmpty(content)) {
            params.put("content", content);
        }
        if (StringUtils.isNotEmpty(icon)) {
            params.put("icon", icon);
        }
        params.put("showFlag", showFlag == null ? 0 : 1);
        return this.getSqlSession().update(this.getStatement("updateByBenefitCode"), params);
    }
}